<?php
include("check.php");
/*include("check2.php");*/
include_once("../function.php");
include_once("../class/system_class.php");
include_once("../class/ulevel_class.php");
include_once ("../bonus.php");

header("Content-Type: text/html;charset=utf-8");
session_start();
$system=new system_class();
$_sys=$system->system_information(1);
$ulevel=new ulevel_class();
$us=que_select_cl('member',$_SESSION['ID']);
if ($_POST['zhuanzhang']){
    $system=new system_class();
    $_sys=$system->system_information(1);
    $startdate=date("Y-m-d 00:00:00");
    $enddate=date("Y-m-d 23:59:59");
    $sql="select * from zhuanzhang where uid={$us['id']} and zdate BETWEEN '{$startdate}' and '{$enddate}'";
    $query=mysql_query($sql);
    $num=mysql_num_rows($query);


    if($us['fenghao']==1){
        echo "<script language=javascript>alert('你已被封号,不能进行此操作.');window.location.href='?'</script>";
    }else {
        if ($sus = getMemberbyNickName($_POST['snickname'])) {
            if ($sus['id'] == $us['id']) {
                echo "<script language=javascript>alert('输入会员编号有误');window.location.href='?'</script>";
            } else {
                if($sus['ispay']==0){
                    echo "<script language=javascript>alert('该会员未激活,无法转账.');window.location.href='?'</script>";
                }else{
                    $_iul = $ulevel->getulevelbyulevel($sus['ulevel']);
                    $jine = $_POST['jine'];
                    $lx = $_POST['lx'];
                    if ($jine > 0) {
                        if ($lx == 0) {
                            if ($us['mey'] >= $jine) {
                                $us_update['mey'] = $us['mey'] - $jine;
                                $sus_update['mey'] = $sus['mey'] + $jine;
                            } else {
                                echo "<script language=javascript>alert('您的余额不足,无法转账.');window.location.href='?'</script>";
                            }
                        } elseif ($lx == 1) {
                            if ($us['zsq'] >= $jine) {
                                $us_update['zsq'] = $us['zsq'] - $jine;
                                $sus_update['zsq'] = $sus['zsq'] + $jine;
                            } else {
                                echo "<script language=javascript>alert('您的余额不足,无法转账.');window.location.href='?'</script>";
                            }
                        } elseif ($lx == 2) {

                            if($us['id']==2||$us['id']==3){
                                if ($us['mey'] >= $jine) {
                                    $sjmey=$jine;
                                    $us_update['mey'] = $us['mey'] - $jine;
                                    $us_update['pv'] = $us['pv'];
                                    $sus_update['mey'] = $sus['mey'] + $sjmey;
                                    //tongbujine($jine,$us['usertel'],2);
                                    // tongbujine($jine,$sus['usertel'],1);
                                } else {
                                    echo "<script language=javascript>alert('您的余额不足,无法转账.');window.location.href='?'</script>";
                                }
                            }else{
                                $yunxu=1;
                                if($us['isbd']==2){
                                    $str=trim($us['repath'],",");
                                    $repath=explode(",",$str);
                                    if(in_array($sus['id'],$repath)&&$sus['isbd']==2){
                                        $yunxu=1;
                                    }else{
                                        $yunxu=0;
                                    }
                                }
                                $zhongrunbi = 0.1;
                                if($yunxu==1) {

                                    //    $us_update['cishanjijin'] = $us['cishanjijin'] + $csjjmey;
                                } else {
                                    echo "<script language=javascript>alert('您的余额不足,无法转账.');window.location.href='?'</script>";
                                }
                            }/*else{
                                        echo "<script language=javascript>alert('您只能给您的上级转账,请重新输入编号.');window.location.href='?'</script>";
                                    }*/

                        } elseif ($lx == 3) {
                            if ($us['pv'] >= $jine) {
                                if ($_iul['yl10'] < $sus['pv'] + $jine) {
                                    $cha = $_iul['yl10'] - $sus['pv'];
                                    if ($cha < $jine) {
                                        echo "<script language=javascript>alert('对方只能接受" . $cha . "积分,无法转账.');window.location.href='?'</script>";
                                    }
                                } else {
                                    $sus_update['pv'] = $sus['pv'] + $jine;
                                    $us_update['pv'] = $us['pv'] - $jine;
                                    if($_sys['fengding']==2){
                                        $us_update['fengding'] = $us['fengding'] + $jine*$_sys['danjia'];
                                    }


                                }
                            } else {
                                echo "<script language=javascript>alert('您的余额不足,无法转账.');window.location.href='?'</script>";
                            }
                        }
                        if ($jine % 100 == 0) {
                            edit_update_cl('member', $us_update, $us['id']);
                            edit_update_cl('member', $sus_update, $sus['id']);
                            /*         $isalert=isfenghao($us['id']);*/
                            $zhuanzhang['uid'] = $us['id'];
                            $zhuanzhang['nickname'] = $us['nickname'];
                            $zhuanzhang['username'] = $us['username'];
                            $zhuanzhang['sid'] = $sus['id'];
                            $zhuanzhang['snickname'] = $sus['nickname'];
                            $zhuanzhang['susername'] = $sus['username'];
                            $zhuanzhang['jine'] = $jine;
                  //          $zhuanzhang['isqr'] = $st;//实体基金
                  //          $zhuanzhang['jinzhongzi'] = $chongfuxiaofei;//金种子
               //    //         $zhuanzhang['zonghe'] = $zhglf;//综合管理费
                            //      $zhuanzhang['sxf'] = $sxfmey;//手续费
                //            $zhuanzhang['csjjmey'] = $liminbi;//力民币
                            //        $zhuanzhang['szzcmey'] = $szzcmey;//数字资产
                            //       $zhuanzhang['xfjfmey'] = $xfjfmey;//消费积分
                            $zhuanzhang['zdate'] = now();
                            $zhuanzhang['lx'] = $lx;
                            add_insert_cl('zhuanzhang', $zhuanzhang);
                            /// if($isalert==0){
                            echo "<script language=javascript>alert('转账成功.\\n转入会员:" . $sus['nickname'] . "\\n转账金额:" . $jine . "');window.location.href='?'</script>";
                            /*     }else{
                                     echo "<script language=javascript>alert('你被封号');window.location.href='?'</script>";
                                 }*/
                        } else {
                            echo "<script language=javascript>alert('转账金额必须为100的倍数');window.location.href='?'</script>";

                        }
                    } else {
                        echo "<script language=javascript>alert('转账金额不正确,请确认后重新转账');window.location.href='?'</script>";
                    }
                }
            }
        } else {
            echo "<script language=javascript>alert('该会员不存在,请确认后重新转账');window.location.href='?'</script>";
        }
    }
}

if ($_GET['action']=="que" and $_GET['zid']!=""){
    $zj=que_select_cl("zhuanzhang",$_GET['zid']);
    if ($zj['isqr']==0){
        $sus=getMemberbyID($zj['sid']);
        $sus_update['zsq']=$sus['zsq']+$zj['jine'];
        $zj_update['isqr']=1;
        edit_update_cl('member',$sus_update,$sus['id']);
        edit_update_cl('zhuanzhang',$zj_update,$zj['id']);
        echo "<script language=javascript>alert('确认完成.');window.location.href='?'</script>";
    }
}

?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link href="css/table.css" rel="stylesheet" type="text/css">
    <link rel="stylesheet" type="text/css" href="css/style.css" />
    <link rel="stylesheet" type="text/css" href="./awesome/css/font-awesome.min.css"/>
    <link href="css/style1.css" rel="stylesheet" type="text/css">
    <link rel="stylesheet" href="./he/jquery.ui.autocomplete.css">
    <script type="text/javascript" src="./js/jquery.min.js"></script>
    <script src="./js/style.js" type="text/javascript" charset="utf-8"></script>
    <link rel="stylesheet" type="text/css" href="../layui-master/src/css/modules/layer/default/layer.css">
    <script src="../layui-master/src/lay/modules/layer.js"></script>
    <title>货币转帐</title>
    <script language="javascript">
        <!--
        function searchxl() {
            lx=document.form1.lx.value;
            if(lx=="0"){
                document.getElementById('zt1').style.display = "";
                document.getElementById('ct1').style.display = "none";
                document.getElementById('pt1').style.display = "none";
            }else if(lx=="2"){
                document.getElementById('zt1').style.display = "none";
                document.getElementById('ct1').style.display = "";
                document.getElementById('pt1').style.display = "none";
            }else if(lx=="3"){
                document.getElementById('zt1').style.display = "none";
                document.getElementById('ct1').style.display = "none";
                document.getElementById('pt1').style.display = "";
            }
        }
        function CheckForm(){
            jine=document.form1.jine.value;
            lx=document.form1.lx.value;
            snickname=document.form1.snickname.value;
            if(snickname.length == 0){
                alert("温馨提示:\n请输入转入会员.");
                document.form1.snickname.focus();
                return false;
            }
            if(jine.length == 0){
                alert("温馨提示:\n请输入转帐金额.");
                document.form1.jine.focus();
                return false;
            }
            if(jine <= 0){
                alert("温馨提示:\n转帐金额必须大于0.");
                document.form1.jine.focus();
                return false;
            }
            if( 1 ><?=$us['pv']-$us['sgb']?>&&lx==3 ){
                alert("温馨提示:\n当前为最低持有量，不能转换.");
                document.form1.jine.focus();
                return false;
            }
            if(jine<<?=$us['sgb']?>&&lx==3 ){
                alert("温馨提示:\n转账金额不能低于最低持有量！.");
                document.form1.jine.focus();
                return false;
            }
            if(lx==3 &&jine><?=$us['pv']*$_sys['jmf1']/100?>){
                alert("温馨提示:\n积分只能兑换<?=$_sys['jmf1']?>%");
                document.form1.jine.focus();
                return false;
            }
            return true;
        }
        function checknickname(lx)
        {
            var iframe = document.getElementById("iframe");
            var user =  document.getElementById("snickname");
            iframe.src= "checknickname.php?lx="+lx+"&nickname="+user.value;
        }

        function checknum(ob){

            var reg=/^[1-9]{1,}\d*$/;
            if(!reg.test(ob.value)){
                ob.value='';

            }
        }
        function checknumyanzheng(){

            if(CheckForm()){
                jine=document.form1.jine.value;
                snickname=document.form1.snickname.value;
                layer.confirm('确认信息：转入会员编号：'+snickname+'金额：'+jine, {icon: 3, title:'提示'}, function(index){
                    //do something
                    $("#form").submit();
                    layer.close(index);
                    /*    $("form").submit(function () {
                     alert(32313);
                     });
                     */
                });
            }

        }
        -->
    </script>
</head>
<body>
<?php
$title="会员转账";
include_once("./public/header_nav.html");
?>
<form id="form" name="form1"  method="post" action="?" ">
<table  width="100%" cellpadding="3" cellspacing="1" border="0" align="center" class="table1">
    <tr id="zt1" >
        <td width="46%" height="22" align="right"><?=$zhuanzhanglx1?>：</td>
        <td width="54%" align="left"><?=$us['mey']?></td>
    </tr>
    <tr style="display: none">
        <td width="46%" height="22" align="right">报单积分：</td>
        <td width="54%" align="left"><?=$us['zsq']?></td>
    </tr >
    <tr id="ct1" style="display: none">
        <td width="46%" height="22" align="right">积分：</td>
        <td width="54%" align="left"><?=$us['mey']?></td>
    </tr>

    <tr>
        <td height="22" align="right">转入会员编号：</td>
        <td align="left"><input name="snickname" type="text" id="snickname" size="10" maxlength="20">
            <input name="button4" type="button" class="button_blue" id="button4" onclick='checknickname(5);' value="验  证"><iframe name="iframe" id="iframe" width="0" height="0" src="about:blank" style="display:none"></iframe></td>
    </tr>
    <tr>
        <td width="46%" height="22" align="right">转账类型：</td>
        <td width="54%" align="left">
            <select name="lx" id="lx" onchange="searchxl()">
                <?php if($zzison1==1){?>
                    <option value="0"><?=$zhuanzhanglx1?></option>
                <?php }?>
                <?php if($zzison2==1){?>
                    <option value="1"><?=$zhuanzhanglx2?></option>
                <?php }?>
                <!--                    <option value="2"><?/*=$zhuanzhanglx3*/?></option>
                    <option value="3"><?/*=$zhuanzhanglx4*/?></option>-->
            </select></td>
    </tr>
    <tr>
        <td height="22" align="right">转账金额：</td>
        <td align="left"><input name="jine" type="text" id="jine" size="10" maxlength="10" onfocus="if(this.value==0)this.value='';" onblur="if(this.value==0)this.value='';" onkeyup="checknum(this);"/></td>
    </tr>
</table>
<table width="100%">
    <tr >
        <input type="hidden" name="zhuanzhang" value="zhuanzhang">
        <td align="center"><input name="zhuanzhang"  type="button" class="button_green" value="转  账" onclick="checknumyanzheng()"></td>
    </tr>
</table>
<br>
<table width="100%" cellpadding="3" cellspacing="1" border="0" align="center" class="table1">
    <tr>
        <td height="20" colspan="15" align="center"> 转 帐 记 录</td>
    </tr>
    <tr>
        <td align="center">转出会员</td>
        <td align="center">转出会员姓名</td>
        <td align="center">转入会员</td>
        <td align="center">转入会员姓名</td>
        <td align="center">转帐金额</td>
        <!--            <td align="center">综合管理费</td>
                    <td align="center">实体基金</td>
                    <td align="center">金种子</td>
                    <td align="center">力民币</td>-->
        <td align="center">转帐类型</td>
        <td align="center">转帐时间</td>
        <td style="display:none" align="center">状态</td>
    </tr>
    <?php
    $pagesize = 10; //设置每页记录数
    $sql = "SELECT * FROM `zhuanzhang` WHERE uid=".$_SESSION['ID']." or sid=".$_SESSION['ID']."";
    if($query = mysql_query($sql)){
        $sum = mysql_num_rows($query); //计算总记录数
    }else{
        $sum=0;
    }
    if($sum % $pagesize == 0) //计算总页数
        $total = (int)($sum/$pagesize);
    else
        $total = (int)($sum/$pagesize) + 1;
    if (isset($_GET['page'])) //获得页码
    {
        $p = (int)$_GET['page'];
    }
    else
    {
        $p = 1;
    }
    if ($p>$total){
        $p=$total;
    }
    $start = $pagesize * ($p - 1); //计算起始记录
    $sql = "SELECT * FROM `zhuanzhang` WHERE uid=".$_SESSION['ID']." or sid=".$_SESSION['ID']." order by id desc limit ".$start.",".$pagesize;
    if($query = mysql_query($sql)){
        while ($row=mysql_fetch_array($query)){
            ?>
            <tr>
                <td align="center"><?=$row['nickname']?></td>
                <td align="center"><?=$row['username']?></td>
                <td align="center"><?=$row['snickname']?></td>
                <td align="center"><?=$row['susername']?></td>
                <td align="center"><?=$row['jine']?></td>
                <!--                    <td align="center"><?/*=$row['zonghe']*/?></td>
                    <td align="center"><?/*=$row['isqr']*/?></td>
                    <td align="center"><?/*=$row['jinzhongzi']*/?></td>
                    <td align="center"><?/*=$row['csjjmey']*/?></td>-->
                <td  align="center"><?php if ($row['lx']==0){ echo $zhuanzhanglx1; }elseif($row['lx']==1){echo $zhuanzhanglx2; }elseif($row['lx']==2){echo $zhuanzhanglx3; }elseif($row['lx']==3){ echo $zhuanzhanglx4; }?></td>
                <td align="center"><?=$row['zdate']?></td>
                <td style="display:none" align="center"><?php if($row['isqr']==0){if($row['uid']==$_SESSION['ID']){?>未确认<?php }else{ ?><a href="?action=que&zid=<?=$row['id']?>">未确认</a><?php } }else{?>已确认<?php }?></td>
            </tr>
            <?php
        }
    }
    ?>
</table>
<table width="100%" border="0" class="ziti">
    <tr>
        <td align="left">&nbsp;</td>
        <td  style="padding-top: 0.4rem" align="right"><?php echo fenye($p,$pagesize,$sum,$total,$cx)?></td>
    </tr>
</table>
</form>
<?php include_once ("public/footer_nav.html")?>
</body>
</html>